<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>服务通知列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="../../../css/mui.min.css">
    <link rel="stylesheet" href="../../../css/global.css">
    <link rel="stylesheet" href="../../../css/style.css">
    <link rel="stylesheet" href="../../../css/checkbox.css"/>
    <link href="../../../css/task.css" rel="stylesheet"/>
    <style>
        .mui-checkbox input[type=checkbox], .mui-radio input[type=radio] {
            top: 8px;
            right: -10px;
        }
        .item_box .item .name{
            height: auto;
			line-height: initial;
			padding: 5px 17px;
        }
    </style>
    <style type="text/css">
        #div {
            width: 0px;
            height: 0px;
            background: red;
            position: fixed;
            top: 65%;
            left: 50%;
        }

        /*移除底部或顶部三角,需要在删除此代码*/
        .mui-popover .mui-popover-arrow:after {
            width: 0px;
        }
    </style>
</head>

<body>

<div id="div"></div>
<div id="popover" class="mui-popover shadow popover">
    <p class="title" id="title">与您之前的工作计划时间冲突，是否确定？</p>
    <div class="btn_box">

        <span class="fl" onclick="closepop()">取消</span>
        <span class="fr red" id="quedingupdate">确定</span>
    </div>
</div>

<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">服务通知列表</h1>
</header>
<div style="height: 30px;"></div>
<div class="item_box">
    <div class="details_con" id="liebiao">
        <!-- <div class="item">
            <div class="bar">
                <span class="number">1170001<img src="../../../images/icon_3.png" /></span>
                <div class="checkbox">
                    <div class="mui-input-row mui-checkbox">
                        <input name="checkbox1" value="运动" type="checkbox" class="rdss"/>
                        <label></label>
                    </div>
                </div>
            </div>
            <div class="name">
                安徽医科大学第一附属医院
            </div>
            <div class="type">
                <p>提交时间：<span>2020-01-20</span><img src="../../../images/icon_54.png"/></p>
                <p>状态：<span>待接收</span><img src="../../../images/icon_55.png"/></p>
            </div>
        </div>
        <div class="item">
            <div class="bar">
                <span class="number">1170001<img src="../../../images/icon_3.png" /></span>
                <div class="checkbox">
                    <div class="mui-input-row mui-checkbox">
                        <input name="checkbox1" value="运动" type="checkbox" class="rdss"/>
                        <label></label>
                    </div>
                </div>
            </div>
            <div class="name">
                安徽医科大学第一附属医院
            </div>
            <div class="type">
                <p>提交时间：<span>2020-01-20</span><img src="../../../images/icon_54.png"/></p>
                <p>状态：<span>待接收</span><img src="../../../images/icon_55.png"/></p>
            </div>
        </div> -->
    </div>
    <div class="btn_box">

        <span class="fl" id="cancel">取消</span>
        <span class="fr red" id="save">确定</span>
    </div>
    <div style="height: 50px;"></div>
</div>

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../js/mui.min.js"></script>
<script src="../../../js/utils/h.js"></script>
<script src="../../../js/constant.js"></script>
<script src="../../../js/common.js"></script>
<script src="../../../js/utils/base64.js"></script>
<script src="../../../js/utils/md5.js"></script>
<script src="../../../js/utils/sortMap.js"></script>
<script src="../../../js/utils/http.js"></script>
<script src="../../../js/app.js"></script>
<script src="../../../js/sqliteTools.js"></script>
<!-- 基础js end -->


<script type="text/javascript" charset="utf-8">
    //mui初始化
    var ServiceNoticeId
    var serviceNo
    var planId
	var state
	var stateName
    var serviceRole
    var estimatedVisitingTime
    var estimatedWorkingHours
    var estimatedDepartureTime
    var ServiceNoticeIds = "";
    var serviceNos = "";
    var planIds = "";
    (function ($, doc) {
        $.init();

        // 取消方法
        h("#cancel").tap(function () {
            $.back()
        });

        $.plusReady(function () {

            var self = plus.webview.currentWebview();
            // 获取上一个页面传过来的参数并显示到页面
            ServiceNoticeId = self.ServiceNoticeId;
            serviceNo = self.serviceNo;
            planId = self.planId;
			state = self.state;
            serviceRole = self.serviceRole;
            estimatedVisitingTime = self.estimatedVisitingTime;
            estimatedWorkingHours = self.estimatedWorkingHours;
            estimatedDepartureTime = self.estimatedDepartureTime;

            // 获取服务通知类别
            getFWList();

            // 确定按钮方法
            h("#save").tap(function () {
                // 获取checkbox的值
                var ele = document.getElementsByName("checkbox1");
                ServiceNoticeIds = "";
                serviceNos = "";
                planIds = "";
                for (var i = 0; i < ele.length; i++) {
                    if (ele[i].checked) {
                        planIds += ele[i].value + ",";
                        ServiceNoticeIds += document.getElementById(ele[i].value).getAttribute('serviceNoticeId') + ",";
                        serviceNos += document.getElementById(ele[i].value).getAttribute('serviceNo') + ",";
                    }
                }
                // 加上之前页面传过来的参数
                // planIds += planId;
                // ServiceNoticeIds += ServiceNoticeId;
                // serviceNos += serviceNo;
			
				planIds = planIds.slice(0, planIds.length-1);
				ServiceNoticeIds = ServiceNoticeIds.slice(0, ServiceNoticeIds.length-1);
				serviceNos = serviceNos.slice(0, serviceNos.length-1);

				if(serviceNos == ""){
					app.toast("请勾选服务通知");
					return
				}
				app.showWaiting('正在提交...')
                ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsList", {
                    "enginnerId": app.getUser().enginnerId,
                    "estimatedVisitingTime": estimatedVisitingTime,
                    "estimatedDepartureTime": estimatedDepartureTime,
                    "planId": planIds
                }, function (data) {
                    //console.log(JSON.stringify(data))
                    if (data.code == 200) {
                        saveIn()
                    } else {
                        app.closeWaiting()
                        mui("#popover").popover('toggle', document.getElementById("div"));
                    }
                }, function (errorMsg) {
                    app.closeWaiting()
                    app.toast(errorMsg)
                    console.log(JSON.stringify(errorMsg))
                });
            });

            h("#quedingupdate").tap(function () {
                app.showWaiting('正在提交...')
                saveIn()
            })

        });
    }(mui, document));

    function saveIn() {

        ajaxGet(BASE_URL + "cc/PlanDetails/fseAccept", {
            "ServiceNoticeIds": ServiceNoticeIds,
            "serviceNos": serviceNos,
            "planIds": planIds,
            "EnginnerId": app.getUser().enginnerId,
            "serviceRole": serviceRole,
            "StartTime": estimatedVisitingTime,
            "workingHours": estimatedWorkingHours,
            "EndTime": estimatedDepartureTime
        }, function (data) {
            app.closeWaiting()
            if (data.code == 200) {
                var sqliteTool = new sqliteTools();
                var offLineDatas = data.data;
                var enginnerId = app.getUser().enginnerId;
                var fseName = app.getUser().name;
                if (offLineDatas && offLineDatas.length > 0) {
					sqliteTool.openDatabase();
                    for (var i = 0; i < offLineDatas.length; i++) {
                        var offData = offLineDatas[i];
                    	sqliteTool.insertServiceBaseData(offData.serviceNo, offData.serviceNoticeId, offData.planId, offData.customerName, offData.instrumentId, offData.instSn, offData.acceptTime, enginnerId, fseName, offData.serviceType, offData.subServiceType, function (flag) {
                    		console.log("insertServiceBaseData serviceNo: " + offData.serviceNo + ", serviceNoticeId: " + offData.serviceNoticeId + ", planId" + offData.planId + ", inserFlag: " + flag)
                    	})
                    }
					sqliteTool.closeDB();
                }
                app.toast("操作成功")

                var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
                if (indexFSE) {
                    indexFSE.evalJS('getList("0")')
                }

                // 查找上级页面并关闭页面
                var details = plus.webview.getWebviewById('view/service/accept/details.html');
                if (details) {
                    details.close()
                }
                var expectedDoor = plus.webview.getWebviewById('view/service/accept/expectedDoor.html');
                if (expectedDoor) {
                    expectedDoor.close()
                }

                var acceptList = plus.webview.getWebviewById('view/service/assign/acceptList.html');
                if (acceptList) {
                    acceptList.close()
                }

                // 关闭工作台待接受列表
                var toBeAcceptedList = plus.webview.getWebviewById('view/service/notice/toBeAcceptedList.html');
                if (toBeAcceptedList) {
                    toBeAcceptedList.close()
                }

                // 关闭进行中
                var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
                if (conductList) {
                    conductList.close()
                }

                // 关闭工作台查询未关闭服务通知列表
                var notClosedList = plus.webview.getWebviewById('view/service/notice/notClosedList.html');
                if (notClosedList) {
                    notClosedList.close()
                }

                var assignList = plus.webview.getWebviewById('view/service/notice/acceptedList.html');
                if (assignList) {
                    assignList.evalJS('getList()')
                    mui.back()
                } else {
                    var self = plus.webview.currentWebview();
                    var acceptedList = plus.webview.create('/view/service/notice/acceptedList.html', 'view/service/notice/acceptedList.html')
                    acceptedList.show()
                    self.close()
                }

            } else {
				app.toast(data.msg)
			}
        }, function (errorMsg) {
            app.closeWaiting()
            app.toast(errorMsg)
        });
    }

    // 获取服务通知类别
    function getFWList() {
        app.showWaiting('加载中...')
        ajaxGet(BASE_URL + "cc/notice/AssociatedCustomers", {
            "ServiceNoticeId": ServiceNoticeId,
            "EnginnerId": app.getUser().enginnerId,
            "state": "0",
            // "planId": planId
        }, function (data) {
            app.closeWaiting()
            console.log(JSON.stringify(data))
            var html = "";
            h("#liebiao").html("");
            if (data.data != "") {
                for (var i = 0; i < data.data.length; i++) {
                    var dts = data.data[i];
                    var hopeBusinessHours = "";
					var isChecked = "";
                    if (dts.hopeBusinessHours != undefined && dts.hopeBusinessHours != 'undefined' && dts.hopeBusinessHours !="")
                    {
                        hopeBusinessHours = dts.hopeBusinessHours;
                    }
					if (dts.serviceNo == serviceNo){
						isChecked = 'checked';
					}
                    html += '<div class="item">'
                    html += '<div class="bar">'
                    html += '<span class="number">' + dts.serviceNo + '<img src="../../../images/icon_204.png" /></span>'
                    html += '<div class="checkbox">'
                    html += '<div class="mui-input-row mui-checkbox" id="' + dts.id + '" serviceNoticeId=' + dts.serviceNoticeId + ' serviceNo=' + dts.serviceNo + ' >'
                    html += '<input name="checkbox1" value="' + dts.id + '" type="checkbox" class="rdss" '+ isChecked +'/>'
                    html += '<label></label>'
                    html += '</div>'
                    html += '</div>'
                    html += '</div>'
                    html += '<div class="name">'
                    html += dts.customerName
                    html += '</div>'
                    html += '<div class="type">'
                    html += '<p>提交时间：<span>' + dts.createTime + '</span><img src="../../../images/icon_202.png"/></p>'
					//默认0待接受，1已接受，2已签到，3已签离，4已完成,5自动签离，6已拒绝
					state = dts.state;
					if(state == '0'){
						stateName = "待接受";
					}else if(state == '1'){
						stateName = "已接受";
					}else if(state == '2'){
						stateName = "已签到";
					}else if(state == '3'){
						stateName = "已签离";
					}else if(state == '4'){
						stateName = "已完成";
					}else if(state == '5'){
						stateName = "自动签离";
					}else if(state == '6'){
						stateName = "已拒绝";
					}
					html += '<p>状态：<span>'+stateName+'</span><img src="../../../images/icon_205.png"/></p>'
                    html += '<p>服务子类型：<span>' + dts.subServiceType + '<span><img src="../../../images/icon_203.png"/></p>'
                    html += '<p>期望服务时间：<span>' + hopeBusinessHours + '</span><img src="../../../images/icon_202.png"/></p>'
                    html += '</div>'
                    html += '</div>';
                }
                h("#liebiao").html(html);
            }
        }, function (errorMsg) {
            console.log(JSON.stringify(errorMsg))
        });
    }


    function closepop() {
        mui("#popover").popover('hide', document.getElementById("div"));
    }
</script>
<!-- js代码 end -->

</body>

</html>
